window.onload = function  () {
	// 捉到所有图片
	var list_item = document.getElementsByClassName('list_item');
	// 捉到banner,加移进，移出事件
	var banner = document.getElementById('banner');

	//捉到所有点击圆点
	var chick_list_item = document.getElementsByClassName('chick_list_item');

	//num,控制出现哪一张的
	var num=0;

	// 循环跑，根据num来展示哪个图片
	function run () {
		for (var i = 0; i < list_item.length; i++) {
			list_item[i].style.display='none';
			chick_list_item[i].style.backgroundColor='#fff';
		};

		list_item[num].style.display='block';
		chick_list_item[num].style.backgroundColor='#F00';

		num++;

		if(num==list_item.length){
			num=0;
		}
	}
	// 定时器
	var time = setInterval(run, 1000);

	//移进停止定时器
	banner.onmouseover = function  () {
		clearInterval(time);
	}
	//移出开始定时器
	banner.onmouseout = function  () {
		time = setInterval(run, 1000);
	}

	//循环加点击事件
	for (var i = 0; i <chick_list_item.length; i++) {
		addEvent(i);
	};

	//点击哪个圆点，就把num符为哪个值，之后run一下，
	function addEvent (x) {
		chick_list_item[x].onclick = function  () {
			num =x;
			run();
		}
	}

	var  chick_left = document.getElementById('chick_left');
	var  chick_right = document.getElementById('chick_right');

	chick_right.onclick = function  () {
		run();
	}

	chick_left.onclick = function  () {

		if(num==1){
			num = list_item.length-1;
		}else if(num==0){
			num = list_item.length-2;
		}else{
			num-=2;
		}
		
		run();
	}
	
}